import { createRouter, createWebHistory, RouteRecordRaw, useRouter } from 'vue-router'

// import routerData from './routerData'
// console.log(routerData);
const routes = [
  {
    path: '/',
    name: 'Home',
    meta: {
      isShow: false,
      title: "首页"
    },
    component: () => import('../views/Home.vue'),
    children: [
      {
        path: 'all',
        name: 'All',
        meta: {
          isShow: true,
          title: "CNode"
        },
        redirect: to => "/all/tabList",
        component: () => import('../views/CNode/All.vue'),
        children: [
          {
            path: 'tabList',
            name: 'TabList',
            meta: {
              isShow: false,
              title: "数据列表"
            },
            component: () => import('../views/CNode/TabList.vue')
          },
          {
            path: 'NewInsert',
            name: 'NewInsert',
            meta: {
              isShow: false,
              title: "新建文章"
            },
            component: () => import('../views/CNode/NewInsert.vue')
          },
        ]
      },
      {
        path: 'details',
        name: 'Details',
        meta: {
          isShow: false,
          title: "文章详情"
        },
        component: () => import('../views/CNode/Details.vue')
      },
      {
        path: 'UserInfo',
        name: 'UserInfo',
        meta: {
          isShow: false,
          title: "个人资料"
        },
        component: () => import('../views/CNode/UserInfo.vue')
      },
      {
        path: 'typescript',
        name: 'TypeScript',
        meta: {
          isShow: true,
          title: "TS"
        },
        component: () => import('../views/typeScript/TypeScript.vue')
      },
      {
        path: 'about',
        name: 'About',
        meta: {
          isShow: true,
          title: "关于"
        },
        component: () => import('../views/About.vue')
      },
      {
        path: 'Info',
        name: 'Info',
        meta: {
          isShow: true,
          title: "个人信息"
        },
        component: () => import('../views/Info.vue')
      },
    ]
  },
  {
    path: '/Login',
    name: 'Login',
    meta: {
      isShow: false,
      title: "登录"
    },
    component: () => import('../views/Login.vue')
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// router.beforeEach((to, from, next) => {
//   const getRouter = router.getRoutes()
//   console.log(getRouter);
//   // vue3只能逐个添加路由信息
//   // 参数1: 添加给哪个父路由的name名，
//   //参数2: 子路由
//   if (getRouter.length === 2) {
//     routerData.forEach(val => {
//       router.addRoute("Home", val)
//     });
//   }
//   next()
// })
export default router